﻿@using Website.CRUDServices
@using Website.Models.Styling
@using Location = Website.Models.Domain.Location
@model Website.Models.ViewModels.ListView<Activity>
@{
    this.ViewBag.Title = "Netværk";
    this.Layout = "~/Views/_Shared/_Layout.cshtml";
    var users = this.ViewData["Users"] as List<User>;
    var criteriaLocation = this.ViewData["CriteriaLocation"] as Guid?;
    var locations = this.ViewData["Locations"] as List<Location>;
    List<Profile> profiles = this.ViewData["Profiles"] as List<Profile> ?? new List<Profile>();
    List<Guid> criteriaAttendees = this.ViewData["CriteriaProfiles"] as List<Guid> ?? new List<Guid>();
    List<Guid> criteriaSupportForBusinessAttendance = this.ViewData["CriteriaSupportForBusinessAttendance"] as List<Guid> ?? new List<Guid>();
    DefaultSearchFields defaultFields = this.ViewData["DefaultFields"] as DefaultSearchFields ?? new DefaultSearchFields();
    List<Guid> criteriaPresentations = this.ViewData["CriteriaPresentations"] as List<Guid> ?? new List<Guid>();
    List<Presentation> presentations = this.ViewData["Presentations"] as List<Presentation> ?? new List<Presentation>();
    var criteriaOrganizer = this.ViewData["CriteriaOrganizer"] as Guid? ?? null;
    var criteriaNetworkType = this.ViewData["CriteriaNetworkType"] as string ?? string.Empty;
    var networkTypes = new List<dynamic>()
    {
        new { NType = "IsNetworkingEvent", Name = "Netværksmøde"},
        new { NType = "IsConferenceEvent", Name = "Konference"},
        new { NType = "IsDelegationTravel", Name = "Delegationsrejse"},
        new { NType = "IsProductLaunch", Name = "Produkt lancering"}
    };
    
    /*
     his.ViewData["CriteriaLocation"] = location;
            this.ViewData["CriteriaNetworkType"] = networkType;
            this.ViewData["CriteriaOrganizer"] = organizer;
            this.ViewData["CriteriaProfiles"] = profiles ?? new List<Guid>();
            this.ViewData["CriteriaPresentations"] = presentations ?? new List<Guid>();
            this.ViewData["CriteriaSupportForBusinessAttendance"] = supportForBusinessAttendance ?? new List<Guid>();
     * 
        <input type="radio" name="NetworkType" value="IsNetworkingEvent">Netværksmøde<br />
        <input type="radio" name="NetworkType" value="IsConferenceEvent">Konference<br />
        <input type="radio" name="NetworkType" value="IsDelegationTravel">Delegationsrejse<br />
        <input type="radio" name="NetworkType" value="IsProductLaunch">Produkt lancering<br />
     * */
}
<h2>Søgeresultat - @ViewBag.Title</h2>

<fieldset class="searchCriterias">
    <legend>Søgning</legend>
    <table>    
        <tr>
            <td>Type:</td><td>@ViewBag.Title</td>
        </tr>
        <tr><td>Antal resultater i alt: </td><td>@Model.TotalRows</td></tr>
        @if (criteriaLocation.HasValue && criteriaLocation.Value != Guid.Empty)
        {
            <tr><td>Lokation: </td><td>@locations.Single(x => x.ID == criteriaLocation.Value).Name</td></tr>
        }
        @if (criteriaPresentations.Any())
        {
            <tr><td>Præsentationer: </td>
                <td>
                    @foreach (Presentation pres in presentations.Where(x => criteriaPresentations.Contains(x.ID)).OrderBy(x => x.Name))
                    {
                        @pres.Name
                        <br />
                    }
                </td>
            </tr>
        }
        @if (criteriaAttendees.Any())
        {
            <tr>
                <td>Deltagere:</td>
                <td>
                    @foreach (Profile profile in profiles.Where(x => criteriaAttendees.Contains(x.ID)).OrderBy(x => x.Name))
                    {
                        @profile.Name
                        <br />
                    }
                </td>
            </tr>
        }
        @if (criteriaSupportForBusinessAttendance.Any())
        {
            <tr>
                <td>Understøttelse af virksomhedsdeltagelse:</td>
                <td>
                    @foreach (Profile profile in profiles.Where(x => criteriaSupportForBusinessAttendance.Contains(x.ID)).OrderBy(x => x.Name))
                    {
                        @profile.Name
                        <br />
                    }
                </td>
            </tr>
        }
        @if (criteriaOrganizer.HasValue && criteriaOrganizer.Value != Guid.Empty)
        {
            <tr>
                <td>Arrangør:</td>
                <td>
                    @if (profiles.Any(x => x.ID == criteriaOrganizer.Value))
                    {
                        @profiles.Single(x => x.ID == criteriaOrganizer.Value).Name
                    }
                </td>
            </tr>
        }
        @if (criteriaNetworkType != null && networkTypes.Any(x => x.NType == criteriaNetworkType))
        {
            <tr>
                <td>Netværks type:</td>
                <td>
                    @networkTypes.First(x => x.NType == criteriaNetworkType).Name
                </td>
            </tr>
        }
   
        @Html.Partial("~/Views/Reports/_SearchDefaultFieldsParametersTableTR.cshtml", defaultFields)

    </table>
</fieldset>





<table class="tableView">
    <tr>
        @foreach (TableViewHeaderItem item in this.Model.Header.Items)
        {
            <td>
                @Html.Partial("~/Views/_Shared/TableViewHeader.cshtml", item)
            </td>
        }
    </tr>
    @if (this.Model != null)
    {
        foreach (Activity act in this.Model.List)
        {
            Profile organizer = profiles.SingleOrDefault(x => x.ID == act.NA.Organizer);
            List<Location> locs = locations.Where(x => x.ID == act.Location).ToList();
            Location location = locs.Count() > 0 ? locations[0] : null;
            IEnumerable<Presentation> presList = presentations.Where(x => act.NA.Presentations.Contains(x.ID));

        <tr>
            <td>@string.Format("{0:dd-MM-yyyy}", act.TimeOfActivity)</td>
            <td>
                @if (location != null)
                {
                    @location.Name
                }

            </td>
            <td>@act.NA.Attendance</td>
            <td>
                @if (organizer != null)
                {
                    @organizer.Name
                }
            </td>
            <td>
                @act.NA.ProductType
            </td>
            <td style="font-size: 0.7em;">

                @if (presList != null)
                {
                    @Html.Raw(string.Join(",<br/>", presList.Select(x => x.Name)))
                }
            </td>
        </tr>
        }
    }
    <tr><td colspan="@Model.Header.Items.Count()"></td></tr>
</table>